//
//  HDDisplayImgView.swift
//  HuaDaoPeifu
//
//  Created by ZERO on 2018/6/21.
//  Copyright © 2018年 paiyipai. All rights reserved.
//

import UIKit

class HDDisplayImgView: UIView {

    @IBOutlet weak var exImgView: UIImageView!
    
    var shadowView : UIView?
    
    
    static func initHDDisplayImgView(type :NSInteger) -> UIView{
        
        var view = HDDisplayImgView()
        view = UINib(nibName: "HDDisplayImgView", bundle: nil).instantiate(withOwner: self, options: nil).last as! HDDisplayImgView
        
        view.layer.setAffineTransform(CGAffineTransform(scaleX:1.1,y: 1.1))
        
        UIView.animate(withDuration: 0.15, delay:0.01, options: [], animations: {
            ()-> Void in
            //            view.layer.setAffineTransform(CGAffineTransform(scaleX:1.3,y: 1.3))
            view.layer.setAffineTransform(CGAffineTransform(scaleX:1/1.1,y: 1/1.1))
        },completion:{
            (finished:Bool) -> Void in
            
            //                view.layer.setAffineTransform(CGAffineTransform(scaleX:1/1.3,y: 1/1.3))
            
            
        })
        
        
        view.shadowView =  UIView()
        view.shadowView?.backgroundColor = UIColor.black
        view.shadowView?.alpha = 0.3
        view.shadowView?.frame = UIScreen.main.bounds
        
        let tapGesture = UITapGestureRecognizer(target: view,action: #selector(HDIdentityTipsView.dismissAction(_:)))
        view.shadowView?.addGestureRecognizer(tapGesture)
        
        view.frame = CGRect(x: 0, y: 0, width: AppConstant.screenWidth - 30 * 2, height: 220)
        view.center = CGPoint(x:AppConstant.screenWidth / 2, y:AppConstant.screenHeight/2 - 10)
        view.layer.cornerRadius = 5
        view.layer.masksToBounds = true
        
        view.showwindow()
        return view
    }
    
    func showwindow(){
        if (self.superview == nil) {
            UIApplication.shared.keyWindow?.addSubview(self.shadowView!)
            UIApplication.shared.keyWindow?.addSubview(self)
        }
    }
    
    
    
    
    func dismissAction(_ gesture:UITapGestureRecognizer){
        UIView.animate(withDuration: 0.3, animations: {
            self.shadowView?.alpha = 0.3
            
        }) { (BOOL) in
            self.shadowView?.removeFromSuperview()
            
        }
        self.removeFromSuperview()
        
    }


    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
